<template>
  <section id="fork">
    <ma-scroll v-if="forkList.length !== 0"  :down="true" :up="true" :refresh="refresh" :getMore="getFork"  :showMsg="false" :init="init">
          <dynamic v-for="(obj,index) in forkList" @deleteItem="deleteItem" :index="index" :obj="obj" :key="index"></dynamic>
      </ma-scroll>
      <empty v-if="forkList.length === 0" message="您还没有关注哦"></empty>
  </section>
</template>
<script>
import dynamic from "components/dynamic/dynamic_home";
import getFork from "services/community/getFork";
import empty from "components/empty-page";
export default {
  name: "fork",
  components: {
    dynamic,
    empty
  },
  data() {
    return {
      forkList: [],
      index: 5,
      count: 5,
      init:true
    };
  },
  methods: {
    refresh(callback){
      let vm = this;
      vm.index = 0;
         return new Promise(function(resolve, reject) {
        getFork.bind(vm)(
          {
            index: vm.index + "",
            count: vm.count + ""
          },
          res => {
            vm.newArr=res;
            vm.index += vm.count;
               vm.init = true;
               resolve(callback);
          }
        );
      });
    },
    getFork(callback) {
      let vm = this;
         return new Promise(function(resolve, reject) {
        getFork.bind(vm)(
          {
            index: vm.index + "",
            count: vm.count + ""
          },
          res => {
            vm.forkList.push(...res);
            vm.index += vm.count;
               vm.init = true;
               resolve(callback);
          }
        );
      });
    },
    deleteItem(index){
        this.forkList.splice(index,1)
    },
  },
  mounted() {
    getFork.bind(this)({
        index: "0",
        count: "5"
      },res => {
        console.log(res);
        this.forkList = res;
      }
    );
  }
};
</script>
<style>
	#fork #wrapper{
        top: 100px;
    }
    #fork .scroller{
      width: 100%;
    }
</style>
